#!/usr/bin/env node

const rootpath=process.cwd()
const path=require('path')
const args=process.argv.slice(2)
const srcpath=path.join(rootpath,args[0]?args[0]:'')
const destpath=path.join(rootpath,args[1]?args[1]:"")
const {readFileSync,readdirSync,copyFileSync,mkdirSync,existsSync,statSync}=require('fs')
dircopy(srcpath,destpath)
function dircopy(srcpath,destpath){
    if(existsSync(srcpath)){
        if(!existsSync(destpath)){
            mkdirSync(destpath)
        }
        readdirSync(srcpath).map(item=>{
            let nextpath=path.join(srcpath,item)
            if(statSync(nextpath).isDirectory()){
                dircopy(nextpath,path.join(destpath,item))
            }else{
                copyFileSync(nextpath,path.join(destpath,item))
            }
        })
    }else{
       console.log("错误")
    }
}